﻿using System.Collections.Generic;
using System.Data;
using Smatime.Web.DAO.SmatimeDatasetTableAdapters;
using Smatime.Web.Models;

namespace Smatime.Web.DAO
{
    public class CompanyUserRepository :
        BaseRepository<CompanyUser, SmatimeDataset.CompanyUserDataTable, CompanyUserTableAdapter>
    {
        /// <summary>
        ///     get company user by companyid
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public IEnumerable<CompanyUser> GetUserByCompanyId(long id)
        {
            using (var adapter = new CompanyUserTableAdapter())
            {
                using (var table = adapter.GetDataByCompanyId(id))
                {
                    var list = new List<CompanyUser>();
                    foreach (DataRow row in table.Rows)
                    {
                        var userOfCompany = new CompanyUser();
                        userOfCompany.FromDataRow(row);
                        list.Add(userOfCompany);
                    }
                    return list;
                }
            }
        }

    }
}